//
//  DropTableView.m
//  YunGou
//
//  Created by macbook on 16/5/23.
//  Copyright © 2016年 macbook. All rights reserved.
//

#import "DropTableView.h"
#import "AllGoodsCell.h"
#import "LatestKnowCell.h"
#import "CategoryTypeModel.h"

#define AllGoodsIdentifier @"allGoodsIdentifier"
#define LatestKnowIdentifier @"LatestIdentifier"

@interface DropTableView ()<UITableViewDelegate,UITableViewDataSource>
@end

@implementation DropTableView
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.dataSource = self;
        self.delegate = self;
        self.bounces = NO;
        [self registerNib:[UINib nibWithNibName:@"AllGoodsCell" bundle:nil] forCellReuseIdentifier:AllGoodsIdentifier];
        [self registerNib:[UINib nibWithNibName:@"LatestKnowCell" bundle:nil] forCellReuseIdentifier:LatestKnowIdentifier];
        _categoryTypeArray = nil;
    }
    return self;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _categoryTypeArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *baseCell = nil;
    CategoryTypeModel *typeModel = _categoryTypeArray[indexPath.row];
    if (self.selectedTag == 1) {
        AllGoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:AllGoodsIdentifier];
        if (indexPath.row == _selectedRow) {
            cell.iconImage.image = [UIImage imageNamed:@"fl_qbsp_cheng"];
            cell.titLabel.textColor = ThemeColor;
        }else{
            cell.iconImage.image = [UIImage imageNamed:@"fl_qbsp_hui"];
            cell.titLabel.textColor = [UIColor blackColor];
        }
        cell.titLabel.text = typeModel.name;
        baseCell = cell;
    }else{
        LatestKnowCell *cell = [tableView dequeueReusableCellWithIdentifier:LatestKnowIdentifier];
        if (indexPath.row == _selectedRow) {
            cell.titLabel.textColor = ThemeColor;
        }else{
            cell.titLabel.textColor = [UIColor blackColor];
        }
        cell.titLabel.text = typeModel.name;
        baseCell = cell;
    }
    return baseCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    _selectedRow = indexPath.row;
    if (self.dropTableViewBlock) {
        self.dropTableViewBlock(indexPath.row);
    }
}

@end
